package view.guitare;

import java.awt.geom.Ellipse2D;

import model.notes.Note;

public class NoteShapeImpl extends Ellipse2D.Double {

	public static int CIRCLE_RADIUS = 20;
	
	private final String key;
	private final Note note;
	private final int string;
	private final int frette;
	
	public NoteShapeImpl (int string, int frette, Note note) {
		super(NeckPanel.TOP_LEFT_X + (frette-1) * NeckPanel.FRETS_DELTA_X + NeckPanel.FRETS_DELTA_X/2 - CIRCLE_RADIUS / 2, NeckPanel.TOP_LEFT_Y + (string-1) * NeckPanel.STRINGS_DELTA_Y - CIRCLE_RADIUS / 2 + 1, CIRCLE_RADIUS, CIRCLE_RADIUS);
	
		this.key = string + "_" + frette;
		this.note = note;
		this.string = string;
		this.frette = frette;
	}
	
	public String getKey() {
		return this.key;
	}
	
	public Note getNote() {
		return this.note;
	}
	
	public double getCenterX() {
		return Math.rint(NeckPanel.TOP_LEFT_X + (frette-1) * NeckPanel.FRETS_DELTA_X + NeckPanel.FRETS_DELTA_X/2);
	}
	
	public double getCenterY() {
		return Math.rint(NeckPanel.TOP_LEFT_Y + (string-1) * NeckPanel.STRINGS_DELTA_Y);
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj == null || !(obj instanceof NoteShapeImpl)) {
			return false;
		} else {
			return ((NoteShapeImpl) obj).getKey().equals(this.key);
		}
	}
	
	@Override
	public int hashCode() {
		return this.key.hashCode();
	}
}
